package com.gg.user.gguser.dao;

import com.gg.user.gguser.dataobject.GgBusinessOpportunityDtaobject;
import com.gg.user.gguser.dataobject.GgInformationDataobject;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface GgBusinessOpportunityDaoMapper {

    // 直接插入的不是移入走这个
    @Insert("insert into gg_businessopportunity(gg_items_token,gg_bo_name,gg_bo_province,gg_bo_city,gg_bo_areaid,gg_bo_detailed,gg_bo_handle,gg_bo_contact,gg_bo_state,gg_bo_level,gg_bo_gender,gg_bo_position,gg_bo_telephone,gg_bo_fax,gg_bo_mailbox,gg_bo_qq,gg_bo_wechat,gg_bo_remarks,gg_id,gg_id_user,gg_bo_zipcode,gg_bo_website,gg_bo_source) values (#{ggItemsToken},#{ggBoName},#{ggBoProvince},#{ggBoCity},#{ggBoAreaid},#{ggBoDetailed},#{ggBoHandle},#{ggBoContact},#{ggBoState},#{ggBoLevel},#{ggBoGender},#{ggBoPosition},#{ggBoTelephone},#{ggBoFax},#{ggBoMailbox},#{ggBoQq},#{ggBoWechat},#{ggBoRemarks},#{ggId},#{ggIdUser},#{ggBoZipcode},#{ggBoWebsite},#{ggBoSource})")
    Integer addBusinessOpportunity(@Param("ggBoName")String ggBoName, @Param("ggBoProvince")String ggBoProvince, @Param("ggBoCity")String ggBoCity,@Param("ggBoAreaid")String ggBoAreaid, @Param("ggBoDetailed")String ggBoDetailed, @Param("ggBoHandle")String ggBoHandle, @Param("ggBoContact")String ggBoContact, @Param("ggBoState")Integer ggBoState, @Param("ggBoLevel")Integer ggBoLevel, @Param("ggBoGender")String ggBoGender, @Param("ggBoPosition")String ggBoPosition, @Param("ggBoTelephone")String ggBoTelephone, @Param("ggBoFax")String ggBoFax, @Param("ggBoMailbox")String ggBoMailbox, @Param("ggBoQq")String ggBoQq, @Param("ggBoWechat")String ggBoWechat, @Param("ggBoRemarks")String ggBoRemarks, @Param("ggId")String ggId, @Param("ggIdUser")String ggIdUser, @Param("ggItemsToken")String ggItemsToken,@Param("ggBoZipcode")String ggBoZipcode,@Param("ggBoWebsite")String ggBoWebsite,@Param("ggBoSource")String ggBoSource);

    // 从信息移入时候插入
    @Insert("insert into gg_businessopportunity(gg_items_token,gg_bo_name,gg_bo_province,gg_bo_city,gg_bo_detailed,gg_bo_handle,gg_bo_contact,gg_bo_state,gg_bo_level,gg_bo_gender,gg_bo_position,gg_bo_telephone,gg_bo_fax,gg_bo_mailbox,gg_bo_qq,gg_bo_wechat,gg_bo_remarks,gg_id,gg_id_user,gg_bo_time,gg_bo_areaid,gg_bo_zipcode,gg_bo_website,gg_bo_source) values (#{ggItemsToken},#{ggBoName},#{ggBoProvince},#{ggBoCity},#{ggBoDetailed},#{ggBoHandle},#{ggBoContact},#{ggBoState},#{ggBoLevel},#{ggBoGender},#{ggBoPosition},#{ggBoTelephone},#{ggBoFax},#{ggBoMailbox},#{ggBoQq},#{ggBoWechat},#{ggBoRemarks},#{ggId},#{ggIdUser},#{ggITime},#{ggIAreaid},#{ggBoZipcode},#{ggBoWebsite},#{ggBoSource})")
    Integer yaddBusinessOpportunity(@Param("ggItemsToken")String ggItemsToken, @Param("ggBoName")String ggBoName, @Param("ggBoProvince")String ggBoProvince, @Param("ggBoCity")String ggBoCity, @Param("ggBoDetailed")String ggBoDetailed, @Param("ggBoHandle")String ggBoHandle, @Param("ggBoContact")String ggBoContact, @Param("ggBoState")Integer ggBoState, @Param("ggBoLevel")Integer ggBoLevel, @Param("ggBoGender")String ggBoGender, @Param("ggBoPosition")String ggBoPosition, @Param("ggBoTelephone")String ggBoTelephone, @Param("ggBoFax")String ggBoFax, @Param("ggBoMailbox")String ggBoMailbox, @Param("ggBoQq")String ggBoQq, @Param("ggBoWechat")String ggBoWechat, @Param("ggBoRemarks")String ggBoRemarks, @Param("ggId")String ggId, @Param("ggIdUser")String ggIdUser, @Param("ggITime")String ggITime,@Param("ggIAreaid")String ggIAreaid,@Param("ggBoZipcode")String ggBoZipcode,@Param("ggBoWebsite")String ggBoWebsite,@Param("ggBoSource")String ggBoSource);

    // 查询详情
    @Select("select gg_items_token as ggItemsToken,gg_bo_name as ggBoName,gg_bo_province as ggBoProvince,gg_bo_city as ggBoCity,gg_bo_detailed as ggBoDetailed,gg_bo_handle as ggBoHandle,gg_bo_contact as ggBoContact,gg_bo_state as ggBoState,gg_bo_level as ggBoLevel,gg_bo_gender as ggBoGender,gg_bo_position as ggBoPosition,gg_bo_telephone as ggBoTelephone,gg_bo_fax as ggBoFax,gg_bo_mailbox as ggBoMailbox,gg_bo_qq as ggBoQq,gg_bo_wechat as ggBoWechat,gg_bo_remarks as ggBoRemarks,gg_id as ggId,gg_id_user as ggIdUser,gg_bo_time as ggBoTime, gg_bo_areaid as ggBoAreaid,gg_bo_zipcode as ggBoZipcode,gg_bo_website as ggBoWebsite,gg_bo_source as ggBoSource from gg_businessopportunity where gg_bo_id=#{itemsId}")
    GgBusinessOpportunityDtaobject getBusinessOpportunity(@Param("itemsId")Integer itemsId);

    // 删除信息
    @Delete("delete from gg_businessopportunity where gg_bo_id=#{itemsId}")
    Integer delectGgBusinessOpportunityItems(@Param("itemsId")Integer itemsId);

    // 一共多少个
    //@Select("select count(*) from gg_businessopportunity where gg_id_user=#{ggIdUser}")
    @Select({
            "<script>",
            "select count(*) from gg_businessopportunity where gg_id_user=#{ggIdUser}",
            "<if test='name!=null and name!=\"\"'>",
            "and gg_bo_name like '%${name}%'",
            "</if>",
            "<if test='type!=null and name!=\"\"'>",
            "and gg_bo_level = #{type}",
            "</if>",
            "<if test='state!=null and name!=\"\"'>",
            "and gg_bo_state = #{state}",
            "</if>",
            "<if test='remarks!=null and name!=\"\"'>",
            "and gg_bo_remarks  like '%${remarks}%'",
            "</if>"
            ,"</script>"
    })
    Integer getBusinessOpportunitySelectCount(@Param("ggIdUser")String ggIdUser,@Param("name")String name,@Param("type") Integer type,@Param("state")Integer state,@Param("remarks")String remarks);

    // 列表
    //@Select("select gg_bo_id as ggBoId, gg_items_token as ggItemsToken,gg_bo_name as ggBoName,gg_bo_province as ggBoProvince,gg_bo_city as ggBoCity,gg_bo_detailed as ggBoDetailed,gg_bo_areaid as ggBoAreaid,gg_bo_handle as ggBoHandle,gg_bo_contact as ggBoContact,gg_bo_state as ggBoState,gg_bo_level as ggBoLevel,gg_bo_gender as ggBoGender,gg_bo_position as ggBoPosition,gg_bo_telephone as ggBoTelephone,gg_bo_fax as ggBoFax,gg_bo_mailbox as ggBoMailbox,gg_bo_qq as ggBoQq,gg_bo_wechat as ggBoWechat,gg_bo_remarks as ggBoRemarks,gg_id as ggId,gg_id_user as ggIdUser,gg_bo_time as ggBoTime from gg_businessopportunity order by gg_bo_update desc limit #{page},#{pageNumber}")
    @Select({"<script>",
            "select gg_bo_id as ggBoId, gg_items_token as ggItemsToken,gg_bo_name as ggBoName,gg_bo_province as ggBoProvince,gg_bo_city as ggBoCity,gg_bo_detailed as ggBoDetailed,gg_bo_areaid as ggBoAreaid,gg_bo_handle as ggBoHandle,gg_bo_contact as ggBoContact,gg_bo_state as ggBoState,gg_bo_level as ggBoLevel,gg_bo_gender as ggBoGender,gg_bo_position as ggBoPosition,gg_bo_telephone as ggBoTelephone,gg_bo_fax as ggBoFax,gg_bo_mailbox as ggBoMailbox,gg_bo_qq as ggBoQq,gg_bo_wechat as ggBoWechat,gg_bo_remarks as ggBoRemarks,gg_id as ggId,gg_id_user as ggIdUser,gg_bo_time as ggBoTime from gg_businessopportunity where gg_id_user=#{ggIdUser}",
            "<if test='name!=null and name!=\"\"'>",
            "and gg_bo_name like '%${name}%'",
            "</if>",
            "<if test='type!=null and name!=\"\"'>",
            "and gg_bo_level = #{type}",
            "</if>",
            "<if test='state!=null and name!=\"\"'>",
            "and gg_bo_state = #{state}",
            "</if>",
            "<if test='remarks!=null and name!=\"\"'>",
            "and gg_bo_remarks like '%${remarks}%'",
            "</if>",
            "order by gg_bo_update desc limit #{page},#{pageNumber}"
            ,"</script>"})
    List<GgBusinessOpportunityDtaobject> getInformationSelectList(@Param("page")Integer page, @Param("pageNumber")Integer pageNumber,@Param("ggIdUser")String ggIdUser,@Param("name")String name,@Param("type") Integer type,@Param("state")Integer state,@Param("remarks")String remarks);

    // 公司身份获取自己商机和公司下面的人的
    @Select({
            "<script>",
            "select count(*) from gg_binding gb left join gg_businessopportunity gbo on gb.gg_b_b_user_id = gbo.gg_id or gbo.gg_id=#{ggIdUser} where gbo.gg_id IS NOT NULL and gb.gg_b_d_user_id = #{ggIdUser}",
            "<if test='name!=null and name!=\"\"'>",
            "and gg_bo_name like '%${name}%'",
            "</if>",
            "<if test='type!=null and name!=\"\"'>",
            "and gg_bo_level = #{type}",
            "</if>",
            "<if test='state!=null and name!=\"\"'>",
            "and gg_bo_state = #{state}",
            "</if>",
            "<if test='remarks!=null and name!=\"\"'>",
            "and gg_bo_remarks  like '%${remarks}%'",
            "</if>"
            ,"</script>"
    })
    Integer getBusinessOpportunitySelectCompanyCount(@Param("ggIdUser")String ggIdUser,@Param("name")String name,@Param("type") Integer type,@Param("state")Integer state,@Param("remarks")String remarks);

    @Select({"<script>",
            "select gbo.gg_bo_id as ggBoId,gbo.gg_items_token as ggItemsToken,gbo.gg_bo_name as ggBoName,gbo.gg_bo_province as ggBoProvince,gbo.gg_bo_city as ggBoCity,gbo.gg_bo_detailed as ggBoDetailed,gbo.gg_bo_areaid as ggBoAreaid,gbo.gg_bo_handle as ggBoHandle,gbo.gg_bo_contact as ggBoContact,gbo.gg_bo_state as ggBoState,gbo.gg_bo_level as ggBoLevel,gbo.gg_bo_gender as ggBoGender,gbo.gg_bo_position as ggBoPosition,gbo.gg_bo_telephone as ggBoTelephone,gbo.gg_bo_fax as ggBoFax,gbo.gg_bo_mailbox as ggBoMailbox,gbo.gg_bo_qq as ggBoQq,gbo.gg_bo_wechat as ggBoWechat,gbo.gg_bo_remarks as ggBoRemarks,gbo.gg_id as ggId,gbo.gg_id_user as ggIdUser,gbo.gg_bo_time as ggBoTime from gg_binding gb left join gg_businessopportunity gbo on gb.gg_b_b_user_id = gbo.gg_id or gbo.gg_id=#{ggIdUser} where gbo.gg_id IS NOT NULL and gb.gg_b_d_user_id = #{ggIdUser}",
            "<if test='name!=null and name!=\"\"'>",
            "and gg_bo_name like '%${name}%'",
            "</if>",
            "<if test='type!=null and name!=\"\"'>",
            "and gg_bo_level = #{type}",
            "</if>",
            "<if test='state!=null and name!=\"\"'>",
            "and gg_bo_state = #{state}",
            "</if>",
            "<if test='remarks!=null and name!=\"\"'>",
            "and gg_bo_remarks like '%${remarks}%'",
            "</if>",
            "order by gg_bo_update desc limit #{page},#{pageNumber}"
            ,"</script>"})
    List<GgBusinessOpportunityDtaobject> getInformationSelectListCompany(@Param("page")Integer page, @Param("pageNumber")Integer pageNumber,@Param("ggIdUser")String ggIdUser,@Param("name")String name,@Param("type") Integer type,@Param("state")Integer state,@Param("remarks")String remarks);


    // 查看商机详情
    @Select("select gg_bo_name as ggBoName,gg_bo_province as ggBoProvince,gg_bo_city as ggBoCity,gg_bo_detailed as ggBoDetailed,gg_bo_areaid as ggBoAreaid,gg_bo_handle as ggBoHandle,gg_bo_contact as ggBoContact,gg_bo_state as ggBoState,gg_bo_level as ggBoLevel,gg_bo_gender as ggBoGender,gg_bo_position as ggBoPosition,gg_bo_telephone as ggBoTelephone,gg_bo_fax as ggBoFax,gg_bo_mailbox as ggBoMailbox,gg_bo_qq as ggBoQq,gg_bo_wechat as ggBoWechat,gg_bo_remarks as ggBoRemarks,gg_id as ggId,gg_id_user as ggIdUser,date_format(gg_bo_time, '%Y-%m-%d %H:%i:%s') as ggBoTime,date_format(gg_bo_update, '%Y-%m-%d %h:%m:%s') as ggBoUpdate,gg_bo_zipcode as ggBoZipcode,gg_bo_website as ggBoWebsite,gg_bo_source as ggBoSource from gg_businessopportunity where gg_id_user=#{ggIdUser} and gg_items_token=#{token}")
    GgBusinessOpportunityDtaobject getBusinessSelectItems(@Param("ggIdUser")String ggIdUser,@Param("token")String token);

    // 修改备注
    @Update("update gg_businessopportunity set gg_bo_remarks=#{count} where gg_items_token=#{token} and gg_id=#{ggId}")
    Integer updateBusinessRemarks(@Param("token")String token,@Param("count")String count,@Param("ggId")String ggId);

    // 修改商机信息
    @Update("update gg_businessopportunity set gg_bo_name=#{ggBoName},gg_bo_province=#{ggBoProvince},gg_bo_city=#{ggBoCity},gg_bo_areaid=#{ggBoAreaid},gg_bo_detailed=#{ggBoDetailed},gg_bo_handle=#{ggBoHandle},gg_bo_contact=#{ggBoContact},gg_bo_level=#{ggBoLevel},gg_bo_state=#{ggBoState},gg_bo_gender=#{ggBoGender},gg_bo_position=#{ggBoPosition},gg_bo_telephone=#{ggBoTelephone},gg_bo_fax=#{ggBoFax},gg_bo_mailbox=#{ggBoMailbox},gg_bo_qq=#{ggBoQq},gg_bo_wechat=#{ggBoWechat},gg_bo_zipcode=#{ggBoZipcode},gg_bo_website=#{ggBoWebsite},gg_bo_source=#{ggBoSource} where gg_items_token=#{ggItemsToken} and gg_id_user=#{ggId}")
    Integer updateBusiness(@Param("ggItemsToken")String ggItemsToken, @Param("ggBoName")String ggBoName, @Param("ggBoProvince")String ggBoProvince, @Param("ggBoCity")String ggBoCity,@Param("ggBoAreaid")String ggBoAreaid, @Param("ggBoDetailed")String ggBoDetailed, @Param("ggBoHandle")String ggBoHandle, @Param("ggBoContact")String ggBoContact, @Param("ggBoState")Integer ggBoState, @Param("ggBoLevel")Integer ggBoLevel, @Param("ggBoGender")String ggBoGender, @Param("ggBoPosition")String ggBoPosition, @Param("ggBoTelephone")String ggBoTelephone, @Param("ggBoFax")String ggBoFax, @Param("ggBoMailbox")String ggBoMailbox, @Param("ggBoQq")String ggBoQq, @Param("ggBoWechat")String ggBoWechat, @Param("ggId")String ggId,@Param("ggBoZipcode")String ggBoZipcode,@Param("ggBoWebsite")String ggBoWebsite,@Param("ggBoSource")String ggBoSource);
}
